#include "sysv_msg.h"

int main(int argc,char *argv[])
{
  int msqid;
  struct msqid_ds info;
  struct msgbuf buf;
 
  msqid = msgget(IPC_PRIVATE,MSG_MODE | IPC_CREAT); 
  if(msqid == -1)
    err_sys("msgget error");
  
  buf.mtype = 1;
  buf.mtext[0] = 1;
  if(msgsnd(msqid,&buf,1,0) ==-1)
    err_sys("msgsnd error"); 

  if(msgctl(msqid,IPC_STAT,&info)==-1)
    err_sys("msgctl stat error");
  
  printf("read-write:%03o,cbytes=%lu qnum=%lu qbytes=%lu\n",
         info.msg_perm.mode & 0777,(ulong_t)info.msg_cbytes,
         (ulong_t)info.msg_qnum,(ulong_t)info.msg_qbytes);
  system("ipcs -a"); 
  if(msgctl(msqid,IPC_RMID,NULL)==-1)
    err_sys("msgctl rmid error");
  return 0;
}
